$(function() {

	var log = {
		initialize: function() {
			this.bindEvent();
			this.onShow();
		},
		onShow: function() {

		},
		bindEvent: function() {
			$('#btn2').on('click', log.sendAjax);
		},
		sendAjax: function() {
			var username = $("#username_log").val();
			var type = 'log';
			$.ajax({
				type: "get",
				url: "http://127.0.0.1:8686",
				async: true,
				dataType: 'text',
				data: {
					"username": username,
					"type": type
				},
				success: function(data) {
					console.log(data);
					var result = JSON.parse(data);
					//$("#p2").html(result[0].username+result[0].password);    //不能忘了这个[0]
					var my_pass = $("#password_log").val();
					console.log(result[0].user_id);
					localStorage.blog_user_id = result[0].user_id;
					if(my_pass == result[0].user_pass) {
						alert("登录成功");
						$('#username_log').val("");
						$('#password_log').val("");
						localStorage.blog_user_name = username;    //保存用户名
						location.href = 'index.html';
					} else {
						$("#p2").html("密码错误");
					}
				}
			});
		}
	}

	log.initialize();
});